package d2_exception;

public class ExceptionTest2 {
    public static void main(String[] args) {
//        try {
//            saveAge(1666);
//        } catch (Exception e) {
//            e.printStackTrace();
//            System.out.println(e.getMessage());
//        }
        try {
            saveAge(2666);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("bug");
        }
    }
    public static void saveAge(int age) {
        if (age > 0 && age < 10) {
            System.out.println("年龄为"+age);
        }
        else{
            throw new AgeIllegalRuntimeException("/age is illegal,your age is "+age);
        }
    }
    public static void saveAge2(int age) throws AgeIllegalException {
        if (age > 0 && age < 10) {
            System.out.println("年龄为"+age);
        }
        else{
            throw new AgeIllegalException("/age is illegal,your age is "+age);
        }
    }
}
